//
//  ViewController.m
//  AliShortVideo
//
//  Created by DarkWorld on 2021/11/26.
//

#import "ViewController.h"
#import "AlivcShortVideoRoute.h"
#import "AliyunMediaConfig.h"
#import "FUManager.h"
#import "AlivcShortVideoPlayViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"首页");
  
    [self addRecordButton];
    [self addPlayVideoButton];
    // Do any additional setup after loading the view.
}
#pragma mark - UI
- (void)addRecordButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 100, 50);
    button.backgroundColor = kRandomColor;
    [button addTarget:self action:@selector(btnRecordAction) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"录制" forState:UIControlStateNormal];
    [self.view addSubview:button];
}

- (void)addPlayVideoButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 200, 100, 50);
    button.backgroundColor = kRandomColor;
    [button setTitle:@"播放" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnPlayVideoAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
#pragma mark - Action
- (void)btnRecordAction
{
    [[FUManager shareManager] loadItems];
    AliyunMediaConfig *config = [AliyunMediaConfig defaultConfig];
    config.beautyType = AlivcBeautyTypeFaceUnity;
    config.minDuration = 2.0;
    config.maxDuration = 3*60.0;
    config.fps = 25;
    config.gop = 5;
    config.cutMode = AliyunMediaCutModeScaleAspectFill;
    config.videoOnly = NO;
    config.backgroundColor = [UIColor blackColor];
    [[AlivcShortVideoRoute shared] registerMediaConfig:config];
    UIViewController *recordVC = [[AlivcShortVideoRoute shared] alivcViewControllerWithType:AlivcViewControlRecord];
    [recordVC setValue:config forKey:@"quVideo"];
    recordVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:recordVC animated:YES];
}
- (void)btnPlayVideoAction
{
    AlivcShortVideoPlayViewController *targetVC = [[AlivcShortVideoPlayViewController alloc] init];
    targetVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:targetVC animated:YES];
}

@end
